package main.java.com.lee.threadlocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/12/14
 */
public class Demo2 {

	static ThreadLocal<Integer> local = new ThreadLocal<>();
	public static void main(String[] args) {

		ExecutorService executor = Executors.newFixedThreadPool(2);
		IntStream.rangeClosed(1, 10).forEach(i->{
			executor.submit(() -> {
				local.set(i);

				print();
			});
		});
		executor.shutdown();
	}

	private static void print() {
		System.out.println("通过threadLocal传递变量: " + local.get());
		local.remove();
	}
}
